/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/



#if !defined(AFX_TEXTGL_H__4DACBB86_9EFC_11D4_8A95_D4B14EEC3D7F__INCLUDED_)
#define AFX_TEXTGL_H__4DACBB86_9EFC_11D4_8A95_D4B14EEC3D7F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/core/PGLFont.h>
#include <pgl/core/PGLObject.h>
#include <pgl/core/PGLCoord2D.h>

/*! 
	\defgroup PGLTextGroup Texts, axes.
	\ingroup PGLObjectGroup
*/

/*! \brief A text object.

\ingroup PGLTextGroup
A string associated to a font.
*/
class PGLCORE_EXT_CLASS CPGLText : public CPGLObject  
{
PGL_DECLARE_DYNCREATE(CPGLText);
public:
	//! \name Constructors
	//@{
	//!  default constructor
	CPGLText(LPCTSTR _text=_T(""), const CPGLColor& textColor = CPGLColor::GetClassicColor( CPGLColor::Black ));
	CPGLText(const CPGLText& t){ *this=t;};
	CPGLText& operator=(const CPGLText& t);
	//!  destructor
	virtual ~CPGLText(){};
	//@}

	//! \brief returns the bounding box
	virtual void GetUnionExtent(gfxinterface::CGfxInterface& gfx, CPGLRectD& rExtent);
	//! Computes bounding box
	virtual void UpdateExtent(gfxinterface::CGfxInterface& gfx);

	//! \name Dimension getters
	//@{
	//! returns the width in pixels of the text (taking into account the rotation)
	double GetPixelWidth() const;
	//! returns the height in pixels of the text (taking into account the rotation)
	double GetPixelHeight() const;
	//! returns distance in pixels from the anchor to the bottom (taking into account the rotation)
	double GetPixelAnchorToBottom() const;
	//! returns distance in pixels from the anchor to the top (taking into account the rotation)
	double GetPixelAnchorToTop() const;
	//! returns distance in pixels from the anchor to the right (taking into account the rotation)
	double GetPixelAnchorToRight() const;
	//! returns distance in pixels from the anchor to the left (taking into account the rotation)
	double GetPixelAnchorToLeft() const;
	//@}

	//! \name GUI
	//@{
	//! Add property page to property sheet
	virtual void AddPropertyPage(CPropertySheet* pPropSheet);
	//@}

	//! \name Font
	//@{
	//! Returns the font object
	CPGLFont& GetFont() {	return m_font;};
	//! Returns the font object
	const CPGLFont& GetFont() const {	return m_font;};
	//@}

	//! \name Attributes
	//@{
	//! Set text
	void SetString(LPCTSTR _text)							{	m_sText=_text;};
	//! Returns text
	LPCTSTR GetString() const								{ return m_sText;};
	//! Sets the positiono
	void SetPosition( const CPGLCoord2D& pos)				{	m_position=pos;};
	//! Return position, const
	const CPGLCoord2D& GetPosition() const					{	return m_position;};
	//! Return position
	CPGLCoord2D& GetPosition()								{	return m_position;};
	//! Sets text angle (in degree, ccw)
	void SetAngle( float angle)								{	m_fAngle = angle - ((int)floor(angle/360) )*360; if (m_fAngle<0) m_fAngle+=360;};
	//! Returns angle (degrees, ccw)
	float GetAngle() const									{	return m_fAngle;};
	//! Sets align (left, right, center)
	gfxinterface::ETextAlignment GetAlign() const			{	return m_eAlign;};
	//! Returns align type
	void SetAlign(gfxinterface::ETextAlignment _eAlign)		{	m_eAlign = _eAlign;};
	//@}

	// plotting
	virtual void PlotGfx(gfxinterface::CGfxInterface& gfx);

	//! \name Scripting
	//@{
	enum ETextProp
	{
		TextPropUnknow,
		TextPropString,
		TextPropPosition,
		TextPropAngle,
		TextPropAlign,
		TextPropFont
	};
	PGL_DECLARE_SCRIPTING(Text);
	//@}

	//! \name Serialization and debugging
	//@{
	//! Serialize
	virtual void SerializeXML(CPGLArchive& ar);
	#ifdef _DEBUG
		//! MFC Dump
	    virtual void Dump( CDumpContext& dc ) const;
		//! MFC AssertValid
	    virtual void AssertValid() const;    // Override
	#endif
	//@}

private:
	//! \name Attributes
	//@{
	//!  pointer to font
	CPGLFont m_font;
	//! align type : left, center, right
	gfxinterface::ETextAlignment m_eAlign;
	//! text
	CString m_sText;
	//! position
	CPGLCoord2D m_position;
	//! Angle ( counter clock-wize starting at 0 = horizontal) in DEGRES !
	float m_fAngle;
	//! pixel size
	POINTFLOAT m_PixelSize;
	//@}
};

PGL_DECLARE_SMARTPTR( CPGLText );

#endif // !defined(AFX_TEXTGL_H__4DACBB86_9EFC_11D4_8A95_D4B14EEC3D7F__INCLUDED_)
